<?php
class BackupController extends AppController {
	var $name = 'Backup';
	var $uses = array();
	var $permissions = array(
		'backup'	=> array('admin','manag')
	);	

	
	function compressed(){
		$file = 'files/'.HOST.'/database_backup_'.date(' YmdHis ').'.gz';
		file_put_contents($file, gzencode( file_get_contents('../database/'.HOST.'/default.'.HOST.'.db'),9));

		$this->Email->to = $this->Session->read("Auth.User.email");  
	    $this->Email->subject = __("Database Backup",true);
	    $this->Email->from = "Administrator <{$this->Session->read("Auth.User.email")}>";		
		$this->Email->attachments = array(  $file  );
//		$this->Email->sendAs = 'both'; // because we like to send pretty mail
//		$this->Email->delivery = 'debug';
	    $this->Email->send();	
	    	
	    $this->Session->setFlash(__("Database backup has been saved", true));
		$this->redirect($this->referer());
	}
}
?>